public class Computer
{
    private final String name;
    private final Component[] components;
    private final int price;

    private int sumPrice()
    {
        int price = 0;
        for (int i = 0; i < components.length; i++)
        {
            price += components[i].getPrice();
        }
        return price;
    }

    Computer(String name, Component[] components)
    {
        this.name = name;
        this.components = components;
        this.price = sumPrice();
    }

    public int getPrice()
    {
        return price;
    }

    public String getName()
    {
        return name;
    }

    public String getInfo()
    {
        String info = "电脑名称：" + this.name + " 价格:" + this.price + "\n";
        info += "组件信息：\n";
        for (int i = 0; i < components.length; i++)
        {
            info += "          " + components[i].getInfo() + "\n";
        }
        return info;
    }

    public String work()
    {
        String workinfo = "";
        for (int i = 0; i < components.length; i++)
        {
            workinfo += components[i].work() + "\n";
        }
        return workinfo;
    }
}
